home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / keybind / name.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  3.9 KB  |  185 lines

  1. /*{{{}}}*/
  2. /*{{{  #includes*/
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. #define NAME_C
  9.  
  10. #include "keybind.h"
  11. #include <h/envvar_str.h>
  12. #include <h/lg.h>
  13. #include <lib/ori_add_lib.h>
  14. /*}}}  */
  15.  
  16. /*{{{  keywords*/
  17. #include "namelist.h"
  18. /*}}}  */
  19.  
  20. /*{{{  name2func*/
  21. public KEYNAME *name2func(unsigned char *name)
  22. {
  23.   int n,diff;
  24.  
  25.   for (n=0,diff=S_bindings;;)
  26.    { if (n+diff<N_bindings)
  27.       { int d;
  28.  
  29.         d=ustrcmp(bindings[n+diff].name,name);
  30.         if (d==0 && bindings[n+diff].use)
  31.            return(bindings+n+diff);
  32.         else if (d<0)
  33.            n+=diff;
  34.       }
  35.      if (diff) diff=diff>>1; else break;
  36.    }
  37.  
  38.   return(0);
  39. }
  40. /*}}}  */
  41. /*{{{  name2keyword*/
  42. public keywords const *name2keyword(unsigned char *name)
  43. {
  44.   int n,diff;
  45.  
  46.   for (n=0,diff=S_keytab;;)
  47.    { if (n+diff<N_keytab)
  48.       { int d;
  49.  
  50.         d=ustrcmp(keytab[n+diff].name,name);
  51.         if (d==0)
  52.            return(keytab+n+diff);
  53.         else if (d<0)
  54.            n+=diff;
  55.       }
  56.      if (diff) diff=diff>>1; else break;
  57.    }
  58.  
  59.   return(0);
  60. }
  61. /*}}}  */
  62. /*{{{  history table*/
  63. /*{{{  type history_list*/
  64. typedef struct history_list
  65.  { char *name;
  66.    histories id;
  67.    struct history_list *next;
  68.  } history_list;
  69. /*}}}  */
  70. /*{{{  list of known histories*/
  71. private history_list history_field[]=
  72. {{NO_HIST,    no_history,    &(history_field[1])},
  73.  {MISC_HIST,    misc_history,    &(history_field[2])},
  74.  {FILE_HIST,    file_history,    &(history_field[3])},
  75.  {SHELL_HIST,    shell_history,    &(history_field[4])},
  76.  {SEARCH_HIST,    search_history,    &(history_field[5])},
  77.  {ERR_HIST,    error_history,    &(history_field[6])},
  78.  {ARG_HIST,    arg_history,    &(history_field[7])},
  79.  {MATCH_HIST,    match_history,    &(history_field[8])},
  80.  {NO_MATCH_HIST,nomatch_history,&(history_field[9])},
  81.  {REPL_HIST,    replace_history,0}
  82. };
  83. private history_list *h_list=history_field;
  84. private histories new_history=user_history;
  85. /*}}}  */
  86.  
  87. public histories name_to_history(tokens t, boolean define)
  88. { histories ret;
  89.  
  90.   if (t==DEFAULT)
  91.      return(default_history);
  92.   ret=unknown_history;
  93.   if (t==NAME || t==OPCODE || t==OPERATION)
  94.    /*{{{  search in list*/
  95.    { history_list *x;
  96.  
  97.      x=h_list;
  98.      while (x)
  99.         if (strcmp(x->name,(char*)tk_string))
  100.            x=x->next;
  101.         else
  102.          { ret=x->id;break; }
  103.      if (define && !x)
  104.       { if (verbose_level>0) printf(F_HISTORY,tk_string);
  105.         x=kbd_malloc(sizeof(history_list)+ustrlen(tk_string)+1);
  106.         strcpy(x->name=(char*)(x+1),(char*)tk_string);
  107.         ret=x->id=new_history++;
  108.         x->next=h_list;
  109.         h_list=x;
  110.       }
  111.    }
  112.    /*}}}  */
  113.  
  114.   return(ret);
  115. }
  116. /*}}}  */
  117. /*{{{  name2lg*/
  118. typedef enum
  119.  { F_C_NONE=0,
  120.    LANGTYP
  121.    F_C_USER,
  122.    F_C_TDS,           /* this has to be the last defined language!!! */
  123.    F_C_SIZE
  124.  } f_c_types;
  125. #define LG_DAT(name,st,sl,et,el) name
  126. public char *f_c_name[]={ "None",LANGDATA "User","Inmos",0 };
  127.  
  128. public unsigned char name2lg(unsigned char *lgname)
  129. { f_c_types t;
  130.  
  131.   for (t=F_C_NONE;t<F_C_SIZE;t++)
  132.      if (!strcmp(f_c_name[t],(char*)lgname))
  133.         return((unsigned char)(f_c_name[t][0]));
  134.   return((unsigned char)'\0');
  135. }
  136. /*}}}  */
  137. /*{{{  name2asm*/
  138. public KEYNAME const *name2asm(unsigned char *name)
  139. {
  140.   int n,diff;
  141.  
  142.   for (n=0,diff=S_asm_token;;)
  143.    { if (n+diff<N_asm_token)
  144.       { int d;
  145.  
  146.         d=ustrcmp(asm_token[n+diff].name,name);
  147.         if (d==0 && asm_token[n+diff].use)
  148.            return(asm_token+n+diff);
  149.         else if (d<0)
  150.            n+=diff;
  151.       }
  152.      if (diff) diff=diff>>1; else break;
  153.    }
  154.  
  155.   return(0);
  156. }
  157. /*}}}  */
  158. /*{{{  name2msg*/
  159. public int name2msg(unsigned char *n)
  160. { int msg_no=0;
  161.  
  162.   while (msg_list[msg_no])
  163.      if (!strcmp((char*)n,msg_list[msg_no++]))
  164.         return(msg_no);
  165.   return(-1);
  166. }
  167. /*}}}  */
  168. /*{{{  name_list*/
  169. public void name_list(void)
  170. {
  171.   /*{{{  histories*/
  172.   { history_list *h=history_field;
  173.  
  174.     while (h) { printf("%s\n",h->name);h=h->next; }
  175.   }
  176.   /*}}}  */
  177.   /*{{{  languages*/
  178.   { int l;
  179.  
  180.     for (l=F_C_NONE;l<=F_C_TDS;l++) printf("%s\n",f_c_name[l]);
  181.   }
  182.   /*}}}  */
  183. }
  184. /*}}}  */
  185.